/**
 * @author   Ivan Andonov
 * @email:   ivan.andonov[at]gmail[dot]com
 *
 * @require  sjs
 * @use      sjs.Utils
 * @optional 
 **/

(function() {
	
	sjs.create('sjs.MouseEvent', {
		
		// CONSTRUCTOR
		initialize : function(e) {
			e = window.event || e;
			
			// PRIVATE VARS
			var oldToString = this.toString;
			
			// PUBLIC VARS
			this.x = (sjs.Utils.isIE() ? sjs.Utils.getPageXScroll() : 0) + (e.pageX || e.clientX);
			this.y = (sjs.Utils.isIE() ? sjs.Utils.getPageYScroll() : 0) + (e.pageY || e.clientY);
			this.offsetX = e.offsetX || e.layerX;
			this.offsetY = e.offsetY || e.layerY;
			this.target = e.target || e.srcElement;
			
			this.delta = 0; // wheel
			if (e.wheelDelta) { // IE/Opera.
				this.delta = e.wheelDelta/120;
				// In Opera 9, delta differs in sign as compared to IE.
				if (window.opera) {
					this.delta = -delta;
				}
			} else if (e.detail) { // Mozilla case.
				// In Mozilla, sign of delta is different than in IE. Also, delta is multiple of 3.
				this.delta = -e.detail/3;
			}
			
			// PUBLIC METHODS
			this.toString = function() {
				return oldToString()+':{ x:'+this.x+' y:'+this.y+' offsetX:'+this.offsetX+' offsetY:'+this.offsetY+' delta:'+this.delta+' target:'+this.target+' }';
			}			
		}
		
	});
	
})();